<template>
  <div>
    <input v-if="flag"  ref="input" type="text" placeholder="请输入要搜索的关键字" />
    <button v-else @click="btn">点击搜索</button>
  </div>
</template>

<script>
// dom.focus() 获取焦点
export default {
  data() {
    return {
      flag: false,
    };
  },
  methods: {
    btn() {
      this.flag = !this.flag;
      this.$nextTick(() => {
        this.$refs.input.focus();
      });
    },
  },
};
</script>

<style>
</style>